package org.jeecgframework.web.system.service.impl;

import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.jeecgframework.web.system.pojo.base.TSRoleUser;
import org.jeecgframework.web.system.pojo.base.TSUser;
import org.jeecgframework.web.system.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 
 * @author 张代浩
 * 
 */
@Service("userService")
@Transactional
public class UserServiceImpl extends CommonServiceImpl implements UserService {

	@Override
	public TSUser checkUserExits(TSUser user) {
		return this.commonDao.getUserByUserIdAndUserNameExits(user);
	}

	@Override
	public String getUserRole(TSUser user) {
		return this.commonDao.getUserRole(user);
	}

	@Override
	public int getUsersOfThisRole(String id) {
		Criteria criteria = getSession().createCriteria(TSRoleUser.class);
		criteria.add(Restrictions.eq("TSRole.id", id));
		int allCounts = ((Long) criteria.setProjection(Projections.rowCount())
				.uniqueResult()).intValue();
		return allCounts;
	}

	@Override
	public void pwdInit(TSUser user, String newPwd) {
		this.commonDao.pwdInit(user, newPwd);
	}

}
